package com.isunland.managesystem.utils;

import com.android.volley.VolleyError;
import com.google.gson.Gson;
import com.isunland.managesystem.R;
import com.isunland.managesystem.base.BaseVolleyActivity;
import com.isunland.managesystem.common.ApiConst;
import com.isunland.managesystem.common.VolleyResponse;
import com.isunland.managesystem.entity.MessageSuccess;
import org.json.JSONException;

/**
 * 对象功能:发送消息和短信的工具类
 * 开发公司: 北京信普达系统工程有限公司
 * 开发人员: wangyanan
 * 创建时间: 2017/6/19 20:52
 */
public class MessageUtil {
  public static void sendReport(BaseVolleyActivity mActivity, String jobNOs, String names,
      String content) {
    if (mActivity == null || MyStringUtil.isEmpty(jobNOs)) return;
    if (MyStringUtil.isEmpty(names)) names = "";
    if (MyStringUtil.isEmpty(content)) content = "";
    String url = ApiConst.getAbsoluteUrl(ApiConst.URL_SEND_MESSAGE);
    ParamsNotEmpty params = new ParamsNotEmpty();
    params.put("content", content);
    params.put("messageType", "3");
    params.put("receiverName", names);
    params.put("userJobNo", jobNOs);
    mActivity.volleyPost(url, params.getParams(), new MessageResponse());
  }

  public static void sendSMS(BaseVolleyActivity mActivity, String jobNOs, String content) {
    if (mActivity == null || MyStringUtil.isEmpty(jobNOs)) return;
    if (MyStringUtil.isEmpty(content)) content = "";
    String url = ApiConst.getAbsoluteUrl(ApiConst.URL_SEND_SMS);
    ParamsNotEmpty params = new ParamsNotEmpty();
    params.put("content", content);
    params.put("userJobNo", jobNOs);
    mActivity.volleyPost(url, params.getParams(), new MessageResponse());
  }

  private static class MessageResponse extends VolleyResponse {
    @Override public void onVolleyError(VolleyError arg0) {
      ToastUtil.show(R.string.sendFail);
    }

    @Override public void onVolleyResponse(String json) throws JSONException {
      ToastUtil.show(new Gson().fromJson(json, MessageSuccess.class).getMessage());
    }
  }
}
